<template>
    <div style=" background-color: #222222; color: #60cf41;">
      <div v-for="(item,idx) in logs" :key="idx">{{item}}</div>
    </div>
</template>

<script>
  import defaultSettings from '@/settings'

  export default {
    name: 'serverlog_console',
    data() {
      return {
        logs:[]
      }
    },
    created() {
      this.init()
    },
    methods: {
      init() {
        let that = this
        let socket = new WebSocket(defaultSettings.serviceUrl.websockt)
        socket.addEventListener('open', function (event) {
            let startMsg = {"type":"fetchLogs","payload":null}
            socket.send(JSON.stringify(startMsg))
        })
        socket.addEventListener('close', function (event) {
        })
        socket.addEventListener('message', function (event) {
          var message = JSON.parse(event.data);
          that.logs.push(message.payload)
          console.error(message)
        })
      }
    }
  }
</script>
